#ifndef HCOMPONENT_H
#define HCOMPONENT_H
#include <QtWidgets>
#include <QtDeclarative>
#include <QSound>

class HLineEdit : public QLineEdit
{
    Q_OBJECT

public:
    HLineEdit(QWidget *parent = 0);
    ~HLineEdit();
protected:
    void               focusInEvent(QFocusEvent *event);
    void               focusOutEvent(QFocusEvent *event);

signals:
    void               sigFocusStateChanged(bool hasFocus);
};

class HComboBox : public QComboBox
{
    Q_OBJECT

public:
    HComboBox(QWidget *parent = 0);
    ~HComboBox();
protected:
    void               focusInEvent(QFocusEvent *event);
    void               focusOutEvent(QFocusEvent *event);

signals:
    void               sigFocusStateChanged(bool hasFocus);
};

class HNoFocusFrameDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    HNoFocusFrameDelegate(QObject * parent = 0);
    ~HNoFocusFrameDelegate();

protected:
    void               paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};

class HFlipSideWidget : public QGraphicsProxyWidget
{

    Q_OBJECT
    Q_PROPERTY(QWidget*   currentContent        READ getCurrentContent     WRITE setCurrentContent     NOTIFY sendCurrentContentChange)

public:
    explicit HFlipSideWidget(QGraphicsItem *parent = 0);
    ~HFlipSideWidget();

    Q_INVOKABLE QWidget*      getCurrentContent();
    Q_INVOKABLE void          setCurrentContent(QWidget* currentContent);

protected:
    void                      mouseMoveEvent(QGraphicsSceneMouseEvent *event);

signals:
    void                      sendCurrentContentChange();
    void                      sendButtonAreaMoved();
};

class HFlipableWidget:public QDeclarativeView
{
    Q_OBJECT
public:
    HFlipableWidget(QWidget *parent = 0);
    ~HFlipableWidget();
    void                    setFrontWidget(QWidget *wndFront);
    void                    setBackWidget(QWidget *wndBack);

protected:
    void                    mousePressEvent(QMouseEvent *event);
    void                    mouseMoveEvent(QMouseEvent *event);
    void                    mouseReleaseEvent(QMouseEvent *event);

private:
    QSize                   calculateContainer(QSize nContentSize);

public slots:
    void                    sltShowFront();
    void                    sltShowBack();

private slots:
    void                    sltButtonAreaMoved();

private:
    int                     m_nCurrentState;//-1:back;0:fliping;1:front;
    QObject                 *m_pRootQML;
    QWidget                 *m_pwndFront;
    QWidget                 *m_pwndBack;

    //deal movable
    bool                     m_bMousePressed;
    QPoint                   m_ptPressed;
    bool                     m_bFirstMove;           //是否为第一次进入move。若点击在了按钮等控件上，HFlipSideWidget
                                                     //会有信号发来，而事件顺序是先进入此类的moveevent，故而，第一次的move舍弃。
};

class HMoveableWidget : public QWidget
{
    Q_OBJECT
public:
    HMoveableWidget(QWidget *parent = 0);
    ~HMoveableWidget();

protected:
    void                      mousePressEvent(QMouseEvent *event);
    void                      mouseMoveEvent(QMouseEvent *event);
    void                      mouseReleaseEvent(QMouseEvent *event);

private:
    bool                      m_bPressed;
    QPoint                    m_posPressed;
};

class HClickableWidget : public QWidget
{
	Q_OBJECT
public:
	HClickableWidget(QWidget *parent = 0);
	~HClickableWidget();

protected:
	void                   mouseDoubleClickEvent(QMouseEvent *event);
	void                   mousePressEvent(QMouseEvent *event);
	void                   mouseReleaseEvent(QMouseEvent *event);
	void                   paintEvent(QPaintEvent *event);
private:
	QPoint                 m_ptPressed;

signals:
	void                   sigMouseClicked();
	void                   sigMouseDoubleClicked();
};

//class HSizeChangeableWidget : public QWidget
//{
//    Q_OBJECT
//public:
//    HSizeChangeableWidget(QWidget *parent = 0);
//    ~HSizeChangeableWidget();
//    void                   setChangeDistance(int nDistance);
//    void                   stopChange();
//    void                   startChange();

//private:
//};

//this widget video will twinkling. Can not be used in video panel.
class HBorderTwinklingWidget : public QWidget
{
    Q_OBJECT
public:
    HBorderTwinklingWidget(QWidget *parent = 0);
    ~HBorderTwinklingWidget();

    void                    setNormalColor(QString strColor);
    void                    setCheckedColor(QString strColor);
    void                    setTwinklingColor(QString strTwinklingColor1,QString strTwinklingColor2);
    void                    setBorderWidth(int nWidth);

    void                    setChecked(bool bChecked);
    void                    startTwinkling();
    void                    stopTwinkling();

protected:
    void                    paintEvent(QPaintEvent *event);

private slots:
    void                    sltTimerTimeOut();

private:
    QString                 m_strBackgroundColor;
    QString                 m_strNormalColor;
    QString                 m_strCheckedColor;
    QString                 m_strTwinklingColor1;
    QString                 m_strTwinklingColor2;
    int                     m_nBorderWidth;

    bool                    m_bChecked;
    bool                    m_bTwinkling;
    bool                    m_bShowTwinkling1;
    QTimer                  *m_pTimer;
	
	QRect                   m_rectLeft;
	QRect                   m_rectUp;
	QRect                   m_rectRight;
	QRect                   m_rectBottom;

    QSound                  *m_pSound;
};

#endif
